package com.it.stringdemo;

import java.util.Scanner;

public class stringdome1 {
    public static void main(String[] args) {
        //需求：已知正确的用户名和密码，请用程序实现模拟用户登录
        //总共给三次机会，登录之后，给出相应的提示
        //1.定义两个变量记录正确的用户名和密码
        String rightUsername = "zhangsan";
        String rightPassword = "123456";

        //键盘录入用户名和密码
        for (int i = 0; i < 3; i++) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入用户名");
            String username = sc.next();
            System.out.println("请输入密码");
            String password = sc.next();

            //比较
            if (username.equals(rightUsername) && password.equals(rightPassword)) {
                System.out.println("用户登陆成功");
            } else {
                if(i==2){
                    System.out.println("账号被锁住，请联系相关人员");
                }else
                System.out.println("用户登录失败,用户名或密码有误，您还剩下"+(2-i)+"次机会");
            }
        }
    }
}
